/*
 * @Descripttion: 
 * @version: 请写项目版本
 * @Author: @cdm
 * @Date: 2021-09-08 13:54:32
 * @LastEditors: @cdm
 * @LastEditTime: 2022-01-12 19:44:55
 * No pains no gains
 */


import { game } from "../../../../script/game/control/game";
import { relationType, relationObject } from "../../../../script/game/gameType";
import figureModel from "../../../../script/game/model/figureModel";
import { ListItem } from "../../../../script/util/ListView/ListItem";
import { ccs } from "../../../../script/util/services";
import { TouchExtend } from "../../../../script/util/TouchExd";
import { touchExd } from "../../../../script/util/TouchExtend";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends ListItem<relationType> {
    
    //标题
    @property(cc.Label)
    title: cc.Label = null;

    //关系
    @property(cc.Label)
    relation: cc.Label = null;

    @property(cc.Label)
    work: cc.Label = null;

    //收入
    @property(cc.Label)
    monthIncome: cc.Label = null;

    @property(cc.Label)
    age: cc.Label = null;

    @property(cc.Sprite)
    icon: cc.Sprite = null;

    @property(cc.ProgressBar)
    intimate: cc.ProgressBar = null;

    @property(cc.Node)
    getInfo: cc.Node = null;

    @property(cc.Node)
    die: cc.Node = null;
    start () {
        
    }
    initItem(data: relationType, index: number) {
        let work = null;
        if(data.hero.work) {
            work = data.hero.works.find(val => val.id == data.hero.work.id);
        }
        this.title.string = data.hero.name;
        this.relation.string = relationObject[data.relation];
        this.monthIncome.string = (!!work? ccs.gf.getOmitNum(work.income): 0 + "");
        this.work.string = (!!work? work.levelName[work.level]: "无业游民");
        this.age.string = data.hero.age + "岁";
        this.intimate.progress = data.intimate/100;
        TouchExtend.touchEndScale(this.getInfo, () => {
            ccs.winMgr.showWin("popHeroInfoWin", {info: data.hero});
        })
        ccs.spriteExd.setSprite(this.icon.node, ccs.resMgr.getHeadIcon(data.hero.sex));
        if(data.hero.lifeTime <= 0) {
            this.die.active = true;
        }else {
            this.die.active = false;
        }

    }
    onItemclick(data: relationType) {
        game.playerMgr.heroInfo.relation.chat = JSON.parse(JSON.stringify(data));
        ccs.winMgr.closeWin("popFamilyWin");
        ccs.winMgr.showWin('popRelationWin', {id: data.id});
    }
}
